<%@page pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

	<link rel="stylesheet" href="${APP_PATH}/bootstrap/css/bootstrap.min.css">
	<link rel="stylesheet" href="${APP_PATH}/css/backstage/font-awesome.min.css">
	<link rel="stylesheet" href="${APP_PATH}/css/backstage/main.css">
	<link rel="stylesheet" href="${APP_PATH}/ztree/zTreeStyle.css">
	<style>
	.tree li {
        list-style-type: none;
		cursor:pointer;
	}
	table tbody tr:nth-child(odd){background:#F4F4F4;}
	table tbody td:nth-child(even){color:#C00;}
	</style>
  </head>
  <body class="container-fluid">
    <div class="container-fluid">
      <div class="row">
          <ol class="breadcrumb">
              <li><a onclick="javascript:history.back(-1);">数据列表</a></li>
              <li class="active">分配许可</li>
          </ol>
			<div class="panel panel-default">
			  <div class="panel-heading">
				<h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
			  </div>
			  <div class="panel-body">
			      <button class="btn btn-success" onclick="doAssign()">分配许可</button>
                  <ul id="permissionTree" class="ztree"></ul>
			  </div>
			</div>
        </div>
      </div>
    </div>

    <script src="${APP_PATH}/jquery/jquery-2.1.1.min.js"></script>
    <script src="${APP_PATH}/bootstrap/js/bootstrap.min.js"></script>
	<script src="${APP_PATH}/script/docs.min.js"></script>
	<script src="${APP_PATH}/layer/layer.js"></script>
	<script src="${APP_PATH}/ztree/jquery.ztree.all-3.5.min.js"></script>
        <script type="text/javascript">
            $(function () {
			    $(".list-group-item").click(function(){
				    if ( $(this).find("ul") ) {
						$(this).toggleClass("tree-closed");
						if ( $(this).hasClass("tree-closed") ) {
							$("ul", this).hide("fast");
						} else {
							$("ul", this).show("fast");
						}
					}
				});
			    
			    var setting = {
		    		check : {
		    		    enable : true
		    		},
		    		async: {
		    			enable: true,
		    			url:"${APP_PATH}/permission/loadAssingnData/${param.id}",
		    			autoParam:["id", "name=n", "level=lv"]
		    		},
					view: {
						selectedMulti: false,
						addDiyDom: function(treeId, treeNode){
							var icoObj = $("#" + treeNode.tId + "_ico"); // tId = permissionTree_1, $("#permissionTree_1_ico")
							if ( treeNode.icon ) {
								icoObj.removeClass("button ico_docu ico_open").addClass(treeNode.icon).css("background","");
							}
       
						}
					}
			    };
			   
			    $.fn.zTree.init($("#permissionTree"), setting);
            });
			function doAssign(){
				//读取当前对象
				var treeObj =  $.fn.zTree.getZTreeObj("permissionTree");
				//获取选中的节点
				var nodes = treeObj.getCheckedNodes(true);
				if (nodes.length == 0){
					layer.msg("请至少选择一个来作为添加", {time:2000, icon:5, shift:6}, function(){
					});
				}else{
					//需要分配许可的角色id
					var a = "roleid=${param.id}";
					$.each(nodes,function (i,nodes){
						//需要分配的许可id
						a+="&permissionids="+nodes.id;
					});
					$.ajax({
						type:"post",
						url:"${APP_PATH}/role/doArrign",
						data:a,
						success:function (result){
							if (result.success){
								layer.msg("许可分配保存成功！", {time:1000,shift:6}, function(){
								
								});
							}else{
								layer.msg("许可分配保存失败，请重新操作！", {time:2000, icon:5, shift:6}, function(){
								});
							}
						}
					});
				}
			}
        </script>
  </body>
</html>
